package com.hzqy.service.activity.load;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.hzqy.persistence.dao.activity.ActivityDrawDao;
import com.hzqy.service.activity.interf.ActivityCountAbstract;
import com.hzqy.service.activity.interf.ActivityUserFactory;
import com.hzqy.web.vo.activity.AcContentActionVo;
import com.hzqy.web.vo.activity.AwardUserVo;
import com.hzqy.web.vo.activity.ResultInfoVo;

public class ActivityAwardUser implements ActivityUserFactory {
	private static final Log LOG = LogFactory.getLog(ActivityAwardUser.class);
	private ActivityCountAbstract activityCount;
	private ActivityDrawDao activityDrawDao ;//=new ActivityDrawDao();// ActivityDrawDao.getInstance();
	public ActivityAwardUser(){}
	public ActivityAwardUser(ActivityCountAbstract activityCount){
		this.activityCount = activityCount;
	}
	public ActivityAwardUser(ActivityDrawDao activityDrawDao){
		this.activityDrawDao=activityDrawDao;
	}
	public String getActivityUserPhone(Map map) {
		return activityDrawDao.getDrawPhone(map);
	}

	public int getActivityUserCount(Map map) {
		map = activityCount.getActivityCount(map);
		if(activityCount instanceof DayActivityCount){
			return activityDrawDao.getDrawCountDay(map);
		}else if(activityCount instanceof WeekActivityCount){
			return activityDrawDao.getDrawCountWeek(map);
		}else{
			return 999999;
		}
	}

	public List activityUserList(Map map) {
		return activityDrawDao.awardUserList(map);
	}

	public int insertActivityUserData(Map map) {
		AwardUserVo awardVo = new AwardUserVo();
		if(map.get("detail") != null){
			awardVo.setF_au_detail((String)map.get("detail"));
		    awardVo.setF_au_grade((String)map.get("grade"));
		}else{
			awardVo.setF_au_detail("错误！");
		    awardVo.setF_au_grade("9999");
		}
       
        if(map.get("phone") == null){
        	awardVo.setF_au_phone("");
		}else{
			awardVo.setF_au_phone((String)map.get("phone"));
		}
        awardVo.setF_au_serverid((String)map.get("serverid"));
        awardVo.setF_au_activityid((String)map.get("activityid"));
        awardVo.setF_au_type((String)map.get("f_au_type"));
        int awardid = 0;
        try{
        	awardid = activityDrawDao.insertAwardResult(awardVo);
        	LOG.debug("插入用户抽奖记录成功");
        }catch(Exception e){
        	LOG.error("插入用户抽奖记录失败",e);
        }
        return awardid;
	}

	public int updateActivityUserData(Map map) {
		int result = 0;
			result = activityDrawDao.updateAwardPhone(map);
		if(result == 1){
			LOG.debug("修改抽奖记录成功");
		}else if(result == 0){
			LOG.debug("修改抽奖记录失败");
		}
		return result;
	}
	public void setActivityCount(ActivityCountAbstract activityCount) {
		this.activityCount = activityCount;
	}
	
	public int getAwardActivityUserCount(Map map) {
		map = activityCount.getActivityCount(map);
		if(activityCount instanceof DayActivityCount){
			return activityDrawDao.getAwardDrawCountDay(map);
		}else if(activityCount instanceof WeekActivityCount){
			return activityDrawDao.getAwardDrawCountWeek(map);
		}else{
			return 0;
		}
	}

}
